<?php
// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
if (!session_id()) { session_start(); }

//get some variables:
if (isset($_GET['attendee_id'])) $requested_attn_id = $_GET['attendee_id'];
if (isset($_GET['action'])) $action = $_GET['action'];

//This is an admin only script so first lets check to make sure the user is valid and an admin. then we can do toher stuff.

if (!check_valid_user() || ($_SESSION['admin'] != 't')) {
	do_html_header('Unauthorized access', staysmall, $uny);
	echo 'You are not logged in or are not authorized to view this page. Please move along.';
	print_brs(24);
	do_html_footer();
	exit;
	}

// Get our variables
if (!empty($_POST)) {
	if (isset($values['coupon_id'])) {
		$values['coupon_id'] = $_POST['coupon_id'];
		}
	$values['description'] = ltrim(trim($_POST['description']));
	$values['amount'] = floatval(trim($_POST['amount']));
	if (empty($values['coupon_code']) || !isset($values['coupon_code']) || $_POST['generate'] = 't') {
		$coupon_code = strtoupper(substr($values['description'], 0, 4));
		$coupon_code .= generate_password(4,true,U);
		$values['coupon_code'] = $coupon_code;
		}
	if (!empty($_POST['active'])) {
		$values['active'] = $_POST['active'];
		} else {
		$values['active'] = 'f';
		}
	}

if (!empty($values) && isset($values)) {
	do_html_header('Manage coupons', staysmall, $uny);
	insert_coupon($values);
	print_array($values);
	do_html_footer(news);
	}

if (!empty($_GET)) {
	$values = get_coupon($_GET['coupon_id']);
	do_html_header('Manage coupons', staysmall, $uny);
	print_coupon_form($values);
	do_html_footer(news);
	}
	
if (empty($_POST)) {
	do_html_header('Manage coupons', staysmall, $uny);
	print_coupon_form();
	do_html_footer(news);
	}